import request from '@/utils/request'
import { getListPayloadBuild } from '../party-userinfo'
import { cached_data } from '@/utils/cache'

const api = 'partyJoin/'
const urlGetAllSteps = `${api}allSteps`
/**
 * 获取全部流程
 *
 * @export
 * @param {*}
 * @return {*}
 */
export function allSteps() {
  return cached_data(urlGetAllSteps, () => request.get(urlGetAllSteps))
}
/**
 * 党员发展情况统计
 *
 * @export
 * @param {*} { group, duty, typeInParty, currentStep, company, page }
 * @return {*}
 */
export function getStatistics({ group, duty, typeInParty, company, currentStep, page }) {
  return request.post(`${api}statistics`, getListPayloadBuild({ group, duty, typeInParty, company, currentStep, page }))
}
/**
 * 查看用户当前进度
 *
 * @export
 * @param {*} { userid }
 * @return {*}
 */
export function info({ userid }) {
  return request.get(`${api}info`, {
    params: {
      userid
    }
  })
}

/**
 * 批量查看用户当前进度简要
 *
 * @export
 * @param {*} { users 用户id列表 }
 * @return {*}
 */
export function infos({ users }) {
  return request.post(`${api}/infos`, Array.isArray(users) ? users : [users])
}

/**
 * 查看用户步骤进度历史
 *
 * @export
 * @param {*} { userid }
 * @return {*}
 */
export function history({ userid }) {
  return request.get(`${api}history`, {
    params: {
      userid
    }
  })
}

/**
 * 提交步骤进度
 *
 * @export
 * @param {*} {
 *  user 用户id,
 *  auth 授权码,
 *  allowOverwrite 是否允许覆盖,
 *  data 调用<build_submit>
 *  }
 * @return {*}
 */
export function submit({ user, auth, allowOverwrite, data }) {
  const payload = {
    data: {
      user,
      step: data
    },
    auth,
    allowOverwrite
  }
  return request.post(`${api}submit`, payload)
}

/**
 * 构造步骤进度
 *
 * @export
 * @param {*} {
 *  id,
 *  recordTime 步骤的记录时间,
 *  conferenceId 关联会议,
 *  content 正文,
 *  status 状态 0无 1通过 2执行中
 *  }
 * @return {*}
 */
export function build_submit({ id, recordTime, conferenceId, content, status }) {
  return { id, recordTime, conferenceId, content, status }
}
